<%@ page contentType="text/html; charset=UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
<%@ taglib uri="http://richfaces.org/a4j" prefix="a4j"%>
<%@ taglib uri="http://richfaces.org/rich" prefix="rich"%>
<%
	String contextRoot = request.getContextPath();
%>
<f:loadBundle basename="properties.messages" var="msg" />
<f:view>
<!doctype html>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<!-- Mimic Internet Explorer 7 -->
	<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7,chrome=1">
	
	<title>SISDEP : Sistema de Informaci<h:outputText value="#{msg.tilde_o}" />n de Espacio P<h:outputText value="#{msg.tilde_u}" />blico</title>
	<meta name="description" content="">
	<meta name="author" content="">
	<link rel="stylesheet" href="<%=contextRoot%>/css/validationEngine.jquery.css" type="text/css">
	<link rel="stylesheet" href="<%=contextRoot%>/css/template.css" type="text/css">
	<link rel="stylesheet" href="<%=contextRoot%>/css/normalize.css">
	<link rel="stylesheet" href="<%=contextRoot%>/css/uniform.css"> <!-- estilos formularios -->
	<link rel="stylesheet" href="<%=contextRoot%>/css/cuerpo.css">	
	<link rel="stylesheet" href="<%=contextRoot%>/css/richCustom.css">
	
</head>
<body>
<div id="marco"> <!--inicio contenedor --> 
<div class="arriba-cuerpo"></div> <!-- Para ver borde redondo en IE -->
<div class="cuerpo">
<a href="<%=contextRoot%>/index.jsf"><img src="<%= contextRoot %>/images/logos.png" /></a>
<div class="clear"></div>
<!-- Menu y Usuario init() -->
	<%@ include file="include/menuUsuario.jsp" %>
<!-- Menu y Usuario end() -->
<div class="clear"></div>
<!-- Formulario --> 
<div id="buscador">
<h2>
    Regulaci<h:outputText value="#{msg.tilde_o}" />n – Registro M<h:outputText value="#{msg.tilde_o}" />dulo: <h:outputText value="#{moduloController.modulo.actualizacionStr eq 'N' ? 'NUEVO' : 'EDICION'}" />
</h2>

<h:form id="moduloCreateForm">
<span class="left" style="margin-left:0px">
<label>C<h:outputText value="#{msg.tilde_o}" />digo<span class="asterisco"> * </span></label>
	<h:inputText id="codigo" size="4" maxlength="4" styleClass="validate[required]"
				value="#{moduloController.modulo.codigo}" />	
</span>
<span class="left" style="margin-left:30px">
<label>Dise<h:outputText value="#{msg.tilde_n}" />o<span class="asterisco"> * </span></label>
 	<h:selectOneMenu id="moduloDiseno" styleClass="validate[required]" 
					value="#{moduloController.modulo.idModuloDiseno}">
					
        <f:selectItem itemLabel="Seleccione..." itemValue=""/>
        <f:selectItems value="#{moduloController.moduloDisenoList}"/>
    </h:selectOneMenu>
</span>
<span class="left" style="margin-left:30px">
<label>Plaqueta Hacienda</label>
	<h:inputText id="plaquetaHacienda" size="4" maxlength="4" 
				value="#{moduloController.modulo.plaquetaHacienda}" />
</span>

<div class="clear" style="margin-left: 400px;"></div>
<br/>

<span class="left" style="margin-left:0px">
	<label>Direcci<h:outputText value="#{msg.tilde_o}" />n<span class="asterisco"> * </span></label>

	<h:inputText id="direccionModulo" size="60" maxlength="60" styleClass="validate[required]"
				value="#{moduloController.modulo.direccionModulo}" />     
		
	<a4j:commandButton id="checkAddressButton"
					 styleClass="botonsmall"
	                 type="submit" 
	                 value="Verificar..." ajaxSingle="true" 
	                 ondblclick="return false;" reRender="checkAddressPanel"
                     action="#{moduloController.checkAddress}" >
                     
		             <a4j:actionparam name="addressParam" value="document.getElementById('moduloCreateForm:direccionModulo').value" 
		                              assignTo="#{moduloController.modulo.direccionModulo}" noEscape="true" />
	</a4j:commandButton>
</span>
<div class="clear" style="margin-left: 400px;"></div>

<span class="left" style="margin-left:0px">
<label>
<a4j:outputPanel id="checkAddressPanel" layout="block" >
	<h:panelGrid columns="1" style="text-align: left;" styleClass="tablapaginacion" >
		<h:outputText id="comunaLabel" 
						value="Barrio: #{moduloController.modulo.codigoBarrio}-#{moduloController.modulo.barrio}" />
		<h:outputText id="barrioLabel" 
						value="Comuna: #{moduloController.modulo.codigoComuna}-#{moduloController.modulo.comuna}" />
    </h:panelGrid>
</a4j:outputPanel>
</label>
</span>

<div class="clear" style="margin-left: 400px;"></div>

<span class="left" style="margin-left:0px">
<label>Tipo de Energ<h:outputText value="#{msg.tilde_i}" />a<span class="asterisco"> * </span></label>
	<h:selectOneMenu id="tipoEnergia" styleClass="validate[required]" 
					value="#{moduloController.modulo.tipoEnergia}">

        <f:selectItem itemLabel="Seleccione..." itemValue=""/>
        <f:selectItems value="#{masterListCache.energyTypeList}"/>
    </h:selectOneMenu>
</span>
<span class="left" style="margin-left:30px">
<label>Cuenta de Cobro</label>
 	<h:selectBooleanCheckbox id="factura" 
			value="#{moduloController.modulo.facturaBool}" />
	
</span>
<a4j:outputPanel rendered="#{moduloController.modulo.actualizacionStr eq 'S'}">
<span class="left" style="margin-left:30px">
<label>Estado de M<h:outputText value="#{msg.tilde_o}" />dulo<span class="asterisco"> * </span></label>
	<h:selectOneMenu id="estadoModulo" styleClass="validate[required]" 
 					onchange="controlOptionalFields(this.id);" 
					value="#{moduloController.modulo.estado}">

        <f:selectItem itemLabel="Seleccione..." itemValue=""/>
        <f:selectItems value="#{moduloController.moduloStatusList}"/>
    </h:selectOneMenu>
</span>
</a4j:outputPanel>

<div class="clear" style="margin-left: 400px;"></div>
<br/>

<a4j:outputPanel rendered="#{moduloController.modulo.actualizacionStr eq 'S'}">
<span class="left" style="margin-left:0px">
<label>Contrato</label>
 	<h:inputText id="contrato" size="20" maxlength="60" 
				value="#{moduloController.modulo.contrato}" />	
</span>
<span class="left" style="margin-left:30px">
<label>Disponibilidad de M<h:outputText value="#{msg.tilde_o}" />dulo</label>
 	<h:inputText id="estadoFinanciero" size="20" maxlength="20" 
				value="#{moduloController.modulo.estadoFinanciero}" />	
</span>
<span class="left" style="margin-left:30px">
<label>Contraprestaci<h:outputText value="#{msg.tilde_o}" />n</label>
 	<h:inputText id="valorContraprestacion" size="10" maxlength="9" styleClass="validate[custom[number]]" 
				value="#{moduloController.modulo.valorContraprestacion}" />		
</span>
<span class="left" style="margin-left:30px">
<label>Valor Mora</label>
 	<h:inputText id="valorMora" size="10" maxlength="9" styleClass="validate[custom[number]]" 
				value="#{moduloController.modulo.valorMora}" />
</span>

<div class="clear" style="margin-left: 400px;"></div>
<br/>
</a4j:outputPanel>

<span class="left" style="margin-left:0px">
<label>Descripci<h:outputText value="#{msg.tilde_o}" />n</label>
 	<h:inputTextarea id="descripcion" rows="5" cols="70"  styleClass="validate[maxSize[255]]"
				value="#{moduloController.modulo.descripcion}" />
</span>
<br/>
<div class="clear">(<span class="asterisco"> * </span>) : Campo Obligatorio.</div>
<div class="clear"></div>

<span class="botones right">
	<h:commandButton id="moduloCreateButton"
				 type="submit" 
                 value="Guardar" 
                 rendered="#{moduloController.modulo.actualizacionStr eq 'N'}" 
                 ondblclick="return false;" 
                 styleClass="botonsmall"
                 action="#{moduloController.create}" >
	</h:commandButton>
	<h:commandButton id="moduloUpdateButton"
				 type="submit" 
                 value="Actualizar" 
                 rendered="#{moduloController.modulo.actualizacionStr eq 'S'}" 
                 ondblclick="return false;" 
                 styleClass="botonsmall"
                 action="#{moduloController.update}" >
	</h:commandButton>
</span>
</h:form>
</div>
<!-- Fin formulario -->
 
   	<span>
		    <h:form id="cancelManageTypeForm">
			<h:commandButton id="cancelCreateModuloButton"							 
                             type="submit" 
                             value="Cancelar" 
                             ondblclick="return false;" 
                             action="#{moduloController.cancelModulo}" >
            </h:commandButton>
            </h:form>
	</span>
	
<div class="clear"></div>

<!-- Fin tabla -->
</div>
<div class="abajo-cuerpo"></div> <!-- Para ver borde redondo en IE -->
</div> <!-- Fin contenedor -->
<div class="footer"></div>
	
	<script src="<%=contextRoot%>/js/jquery/lib/jquery-1.7.2.min.js"></script><!-- De ser 1ro -->
	<script src="<%=contextRoot%>/js/script.js" type="text/javascript"></script><!-- De ser 2do -->
	<script src="<%=contextRoot%>/js/jquery/lib/jquery.uniform.min.js"></script> <!-- formularios --> 
	<script src="<%=contextRoot%>/js/jquery/lib/jquery.validationEngine.js" type="text/javascript" charset="utf-8"></script>
	<script src="<%=contextRoot%>/js/jquery/lib/jquery.validationEngine-es.js" type="text/javascript" charset="utf-8"></script>
	
	<script src="<%=contextRoot%>/js/sisdep.js"	type="text/javascript"></script>
	
	<script type="text/javascript">
	jQ(document).ready(function() {
		jQ("input, select, input:checkbox, input:radio, input:file").uniform();
		jQ("#moduloCreateForm").validationEngine('attach');
		jQ("#moduloCreateForm").bind("jqv.form.result", function(event, errorFound) {
	        if(!errorFound) displayLoadingImage();
	    });
	});
	
	/** Habilita/Deshabilita los campos opcionales de Modulos, dependiendo del Estado seleccionado. */
	function controlOptionalFields(idComponent) {
		var selectedInx = document.getElementById(idComponent).selectedIndex;
		
		if (document.getElementById(idComponent).options[selectedInx].text == "Asignado") {
			document.getElementById("moduloCreateForm:contrato").removeAttribute("disabled");
			document.getElementById("moduloCreateForm:estadoFinanciero").removeAttribute("disabled");
			document.getElementById("moduloCreateForm:valorContraprestacion").removeAttribute("disabled");
			document.getElementById("moduloCreateForm:valorMora").removeAttribute("disabled");
		} else {
			document.getElementById("moduloCreateForm:contrato").value = "";
			document.getElementById("moduloCreateForm:estadoFinanciero").value = "";
			document.getElementById("moduloCreateForm:valorContraprestacion").value = "";
			document.getElementById("moduloCreateForm:valorMora").value = "";
			document.getElementById("moduloCreateForm:contrato").setAttribute("disabled", "true");
			document.getElementById("moduloCreateForm:estadoFinanciero").setAttribute("disabled", "true");
			document.getElementById("moduloCreateForm:valorContraprestacion").setAttribute("disabled", "true");
			document.getElementById("moduloCreateForm:valorMora").setAttribute("disabled", "true");
		}
	}
	</script>
	
	<%@ include file="include/validationStatus.jsp" %>
	<%@ include file="include/modalMessageWindow.jsp" %>
</body>
</html>
</f:view>